home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Workspace / Locus / Source / ErrorReporting.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  148 lines

  1.  
  2. /*
  3.     Copyright 1993  Jeremy Slade.  All rights reserved.
  4. */
  5.  
  6. #import "ErrorReporting.h"
  7. #import <stdarg.h>
  8. #import <stdio.h>
  9.  
  10.  
  11. static unsigned debugLevel = 0;
  12.  
  13. #define MAX_MSG    1024
  14.  
  15.  
  16. @implementation Object ( ErrorReporting )
  17.  
  18.  
  19. + debug:(unsigned)level :(const char *)fmt, ...
  20. /*
  21.     Output a formatted debugging message if level is less than or equal to debugLevel
  22. */
  23. {
  24.     va_list params;
  25.     char buf[MAX_MSG+1];
  26.     
  27.     
  28.     if ( level > debugLevel )
  29.         return ( self );
  30.     
  31.     va_start ( params, fmt );
  32.     vsprintf ( buf, fmt, params );
  33.     va_end ( params );
  34.     
  35.     printf ( buf );
  36.     
  37.     return ( self );
  38. }
  39.  
  40.  
  41.  
  42. - debug:(unsigned)level :(const char *)fmt, ...
  43. /*
  44.     Output a formatted debugging message if level is less than or equal to debugLevel
  45. */
  46. {
  47.     va_list params;
  48.     char buf[MAX_MSG+1];
  49.     
  50.     
  51.     if ( level > debugLevel )
  52.         return ( self );
  53.     
  54.     va_start ( params, fmt );
  55.     vsprintf ( buf, fmt, params );
  56.     va_end ( params );
  57.     
  58.     printf ( buf );
  59.     
  60.     return ( self );
  61. }
  62.  
  63.  
  64.  
  65. + setDebugLevel:(unsigned)level
  66. /*
  67.     Set the debugging message output threshold
  68. */
  69. {
  70.     debugLevel = level;
  71.     return ( self );
  72. }
  73.  
  74.  
  75.  
  76. - setDebugLevel:(unsigned)level
  77. /*
  78.     Set the debugging message output threshold
  79. */
  80. {
  81.     debugLevel = level;
  82.     return ( self );
  83. }
  84.  
  85.  
  86.  
  87. + (unsigned)debugLevel
  88. {
  89.     return ( debugLevel );
  90. }
  91.  
  92.  
  93.  
  94. - (unsigned)debugLevel
  95. {
  96.     return ( debugLevel );
  97. }
  98.  
  99.  
  100.  
  101.  
  102. // -------------------------------------------------------------------------
  103. //   Error Messages
  104. // -------------------------------------------------------------------------
  105.  
  106.  
  107. + errMsg:(const char *)fmt, ...
  108. /*
  109.     Output a formatted error message
  110. */
  111. {
  112.     va_list params;
  113.     char buf[MAX_MSG+1];
  114.     
  115.     
  116.     va_start ( params, fmt );
  117.     vsprintf ( buf, fmt, params );
  118.     va_end ( params );
  119.     
  120.     printf ( buf );
  121.     
  122.     return ( self );
  123. }
  124.  
  125.  
  126.  
  127. - errMsg:(const char *)fmt, ...
  128. /*
  129.     Output a formatted error message
  130. */
  131. {
  132.     va_list params;
  133.     char buf[MAX_MSG+1];
  134.     
  135.     
  136.     va_start ( params, fmt );
  137.     vsprintf ( buf, fmt, params );
  138.     va_end ( params );
  139.     
  140.     printf ( buf );
  141.     
  142.     return ( self );
  143. }
  144.  
  145.  
  146.  
  147. @end
  148.